package aod.android.com.bernay.live;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseFragment;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.live.activity.AddLiveActivity;
import aod.android.com.bernay.live.adapter.LiveAdapter;
import aod.android.com.bernay.live.bean.HomeListBean;
import aod.android.com.bernay.live.bean.LIveListBean;
import aod.android.com.bernay.util.SharePreUtils;
import aod.android.com.bernay.view.activity.PhotoInfoActivity;
import aod.android.com.bernay.view.activity.VideoInfoActivity;
import chen.lion.hilib.image.ImageLoader;
import chen.lion.hilib.util.LogUtils;
import chen.lion.hilib.view.bind.HiView;

/**
 * <p>文件描述：直播页面 <p>
 * <p>作者：${SYC}<p>
 * <p>创建时间：2019/4/3<p>
 */
public class LiveFragment extends BernayBaseFragment implements View.OnClickListener{

    @HiView(R.id.live_lv)
    ListView live_lv;
    List<LIveListBean> lIveListBeans =  new ArrayList<>();
    LiveAdapter liveAdapter;
    @HiView(R.id.add_live_lya)
    LinearLayout add_live_lya;
    HomeListBean homeListBean;
    @Override
    protected int initLayout() {
        return R.layout.frament_live;
    }

    @Override
    protected void initData() {

        initTitle("直播",false);

        initTitle("直播", R.drawable.icon_live_add_live, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goActivity(AddLiveActivity.class);
            }
        });
        getData();
        lIveListBeans = new LIveListBean().setData();

        add_live_lya.setOnClickListener(this);
        live_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle =  new Bundle();
                bundle.putSerializable("liveBean",homeListBean.getData().get(position));
                if(homeListBean.getData().get(position).getType().equals("2")) {
                    goActivity(VideoInfoActivity.class,bundle);
                }else{
                    goActivity(PhotoInfoActivity.class,bundle);
                }
            }
        });


    }

    public void getData(){
        BernayApi.http().getVideoList(SharePreUtils.newInstance(getActivity()).getUserId(),
                SharePreUtils.newInstance(getActivity()).getToken(), "1", "12", new BernayCallback() {
            @Override
            public void onJsonData(String json) {
                Gson gson = new Gson();
                homeListBean =  gson.fromJson(json,HomeListBean.class);
                if(homeListBean.getStatus()==1 && homeListBean.getData()!=null){
                    if(homeListBean.getData().size()!=0){
                        liveAdapter = new LiveAdapter(getActivity(),homeListBean.getData());
                        live_lv.setAdapter(liveAdapter);
                    }
                }
            }
            @Override
            public void onHttpFailure(IOException e) {

            }
        });
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.add_live_lya :

                break;
        }
    }
}
